﻿using System;
using Newtonsoft.Json;

namespace Moose.Common
{
    public class JsonHelper
    {
        public string CrestJsonResultToObj(object obj)
        {
            try
            {
                return JsonConvert.SerializeObject(obj);
            }
            catch (Exception ex)
            {
                throw new Exception("反序列化失败，错误信息：" + ex.Message);
            }
        }

        public T Create<T>(string jsonString)
        {
            try
            {
                return JsonConvert.DeserializeObject<T>(jsonString);
            }
            catch (Exception ex)
            {
                throw new Exception("序列化对象失败，错误信息：" + ex.Message);
            }
        }
    }
}
